import { Route, Routes } from "react-router-dom";
import { server } from "~/mocks/server";
import { dummyDeployment } from "~/__fixtures__/dummy-deployment";
import { render, waitFor, MemoryRouter } from "~~/test-utils";
import { DeploymentDetailPage } from ".";

Element.prototype.scrollIntoView = jest.fn();

beforeAll(() => {
  server.listen();
});

afterEach(() => {
  server.resetHandlers();
});

afterAll(() => {
  server.close();
});

describe("DeploymentDetailPage", () => {
  test("fetch a deployment data and show that data", async () => {
    const { getByText } = render(
      <MemoryRouter
        initialEntries={[`/deployments/${dummyDeployment.id}`]}
        initialIndex={0}
      >
        <Routes>
          <Route
            path="/deployments/:deploymentId"
            element={<DeploymentDetailPage />}
          />
        </Routes>
      </MemoryRouter>
    );

    await waitFor(() => getByText("SUCCESS"));
  });
});
